Skip to content

Feature/fee collected event - #385

Merged
ogazboiz merged 6 commits into
LabsCrypt:mainfrom
Omoboi-dev:feature/fee-collected-event-329
Apr 28, 2026
Merged

Feature/fee collected event#385
ogazboiz merged 6 commits into
LabsCrypt:mainfrom
Omoboi-dev:feature/fee-collected-event-329

Conversation

@Omoboi-dev

Copy link
Copy Markdown
Contributor

closes #329

This PR implements the handling for the fee_collected contract event and introduces treasury fee reporting for administrators. It also resolves several underlying build and type-related issues in the backend to ensure a successful production build.

Key Features

1. Fee Event Indexing & Real-time Updates

  • Event Handler: Implemented handleFeeCollected in SorobanEventWorker to decode and persist fee_collected events emitted during stream creation and top-ups.
  • Real-time SSE: Integrated sseService.broadcastToAdmin to notify administrative subscribers immediately when a protocol fee is collected.
  • Processing Order Safety: Updated the event worker to sort incoming events within a batch, ensuring stream_created events are always processed before fee_collected events to maintain database integrity and foreign key constraints.

2. Administrative Metrics

  • Treasury Reporting: Extended the /v1/admin/metrics endpoint to provide aggregated fee statistics.
  • Token-based Aggregation: Admins can now see total fees collected per token and a specific breakdown for the last 24-hour window.

Technical Fixes & Improvements

  • Build Resolution: Fixed a syntax error in soroban-event-worker.ts (extra closing brace) and resolved an ioredis import conflict for ESM compatibility in redis.ts.
  • Type Safety:
    • Defined proper Request parameter types in stream.controller.ts to fix address property access errors.
    • Exported SSEService class to support named imports in the test suite.
    • Added proper type casting for mocked Prisma methods in stream.test.ts to satisfy TypeScript requirements.
  • Code Quality: All new logic is implemented without additional comments, maintaining the project's existing code style.

Acceptance Criteria Verified

  • fee_collected events are written to the StreamEvent table.
  • Admin metrics include fee totals per token and per 24h window.
  • Real-time stream.fee_collected SSE events are broadcast to admins.
  • Existing event handlers remain unaffected.
  • npm run build completes successfully.

@ogazboiz
ogazboiz merged commit aa8f561 into LabsCrypt:main Apr 28, 2026
6 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add FEE_COLLECTED event handler and treasury fee reporting

2 participants